﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Csla;
using Csla.Data;

namespace Sys.Security
{
    /// <summary>
    /// 用户产品信息的确认
    /// 用户权限列表-缓存此信息
    /// </summary>
    public static class TKUserPurview
    {
        private static List<Puerview> _PurviewList=null;
        public static List<Puerview> PuerviewList1
        {
            get{
                if(_PurviewList==null)
                {
                    LoadPuerview();
                }

                return _PurviewList;
            }
           
        }
        /// <summary>
        /// 加载用户的权限
        /// </summary>
        private static void LoadPuerview()
        {
            _PurviewList = new List<Puerview>();
            ///加载的时候加载列表[操作的四个关键字:A,D,U,C,L]
            ///加载当前用户的权限.
            string Sql = "select * from ve_GetBusinessObjectPower";

            Database DB = DatabaseFactory.CreateDatabase();
            DbCommand CMD = DB.GetSqlStringCommand(Sql);
            var roleList = new Csla.Core.MobileList<string>();

            using (SafeDataReader DR = new SafeDataReader(DB.ExecuteReader(CMD)))
            {

                while (DR.Read())
                {
                   _PurviewList.Add(new Puerview() { UserName = DR.GetString("UserName"), UserRole = DR.GetString("RoleName"), ObjectCode = DR.GetString("ClassName"), Operator = DR.GetString("Operation") });
                }
                

            }
        }

        /// <summary>
        /// 根据类名获取权限,不能根据用户[CSLA是一次性将对象的所有数据缓存]
        /// </summary>
        /// <returns></returns>
        public static List<Puerview> FindPuerviewByClassName(string className)
        {
            if (_PurviewList == null)
            {
                LoadPuerview();
            }
            ///开始获取更加类
            ///
            return _PurviewList;
        }

       
    }
    /// <summary>
    /// 业务对象的权限项
    /// </summary>
     public struct Puerview
     {
         public string UserName;
         public string UserRole;
         public string ObjectCode;
         public string Operator;
     }
}
